# coding: utf-8

################################################################################
#* Licensed Materials - Property of ShaoYang                                   #
#*                                                                             #         
#* OCO Source Materials                                                        #          
#*                                                                             #                 
#* (C) Copyright ShaoYang Corp. 2015 All Rights Reserved                       #
#*                                                                             # 
#* The source code for this program is not published or other-                 #
#* wise divested of its trade secrets, irrespective of what has                #
#* been deposited.                                                             # 
################################################################################

#*******************************************************************************
# Author:shao4phone@gmail.com
# Createdate:Thu May 21 03:51:06 2015
# Lastupd:Thu May 21 03:51:06 2015

# Description
# Updatelog:
# 1. "Init"
#*******************************************************************************

module Query
  module DBModel
    class DBModelObject

    end

    class Patient<DBModelObject
      include Mongoid::Document
      field :patientid,type:String,default:""
      has_many :rawdata,class_name:"RawData",inverse_of: :patient,autosave:true
      has_many :analyseddata,class_name:"AnalysedData",inverse_of: :patient,autosave:true
      index({ id: 1 }, { unique: true })
      store_in collection: "Patients"
      accepts_nested_attributes_for :rawdata, :analyseddata
    end

    class RawData<DBModelObject
      include Mongoid::Document
      belongs_to :patient,class_name:"Patient"
      belongs_to :analyseddata,class_name:"AnalysedData"
      field :stime,type:Time,default:Time.now
      field :etime,type:Time,default:Time.now
      field :url,type:String,default:""
      index({ id: 1 }, { unique: true })
      store_in collection: "RawDatas"
    end

    class AnalysedData<DBModelObject
      include Mongoid::Document
      belongs_to :patient,class_name:"Patient"
      has_many :rawdata,class_name:"RawData",inverse_of: :analyseddata,autosave:true
      has_many :events,class_name:"AnalysedEvent",inverse_of: :analyseddata,autosave:true
      field :stime,type:Time,default:Time.now
      field :etime,type:Time,default:Time.now
      field :url,type:String,default:""
      field :atype,type:String,default:""
      index({ id: 1 }, { unique: true })
      store_in collection: "AnalysedDatas"
    end

    class AnalysedEvent<DBModelObject
      include Mongoid::Document
      field :stime,type:Time,default:Time.now
      field :etime,type:Time,default:Time.now
      belongs_to :analyseddata,class_name:"AnalysedData"
      index({ id: 1 }, { unique: true })
      store_in collection: "AnalysedEvents"
    end

    class AnalysProgram<DBModelObject
      include Mongoid::Document
      field :path,type:String,default:""
      field :minduration,type:Time
      field :overlapQty,type:Integer,default:1
      index({ id: 1 }, { unique: true })
      store_in collection: "AnalysPrograms"
    end

  end
end
